#!/bin/bash
# 哈利波特知识图谱项目启动脚本

# 预设Neo4j连接配置
export NEO4J_URI="bolt://localhost:7687"
export NEO4J_USER="neo4j"
export NEO4J_PASSWORD="gjj030712"
export CSV_PATH="harrypotterkgdata.csv"
export CSV_HAS_HEADERS="False"

echo "=============================================="
echo "  哈利波特知识图谱项目                        "
echo "=============================================="
echo "已配置Neo4j连接信息:"
echo "  地址: $NEO4J_URI"
echo "  用户名: $NEO4J_USER"
echo "  密码: 已预设"
echo "=============================================="

# 数据导入
read -p "是否导入数据? (y/n): " import_choice
if [ "$import_choice" = "y" ] || [ "$import_choice" = "Y" ]; then
    if [ -f "$CSV_PATH" ]; then
        echo "开始导入数据..."
        python neo4j_importer.py
    else
        echo "错误: 未找到数据文件 $CSV_PATH"
        exit 1
    fi
fi

# 启动后端API
read -p "是否启动后端服务? (y/n): " api_choice
if [ "$api_choice" = "y" ] || [ "$api_choice" = "Y" ]; then
    echo "启动后端API服务 (http://localhost:5000)..."
    python backend_api.py &
    echo "后端服务已启动，PID: $!"
fi

# 直接打开前端页面（移除交互询问）
echo "打开前端页面..."
if [[ "$OSTYPE" == "msys"* ]]; then
    start index.html
elif [[ "$OSTYPE" == "darwin"* ]]; then
    open index.html
else
    xdg-open index.html
fi

echo "=============================================="
echo "操作完成"
echo "=============================================="